package com.crazymaker.demo.httpGetter;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import rx.Observable;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

@Slf4j
public class HttpGetterTester
{
    /**
     * 根据实际的地址调整：主要调整订单微服务的IP
     */
    private static final String TEST_URL = "http://192.168.233.128:8092/api/demo/hello/v1";


    @Test
    public void testNoDefer() throws InterruptedException
    {
        AsynHttpGetter asynHttpGetter = new AsynHttpGetter(TEST_URL);

        for (int i = 0; i < 100; i++)
        {
            Observable<String> observable = asynHttpGetter.responceObservable();
            log.info("test starting...." );
            observable
                    .subscribeOn(Schedulers.io())
                    .subscribe(new Action1<String>()
                    {
                        @Override
                        public void call(String s)
                        {
                            log.info("asynHttpGetter s == " + s);
                        }
                    });
        }
        Thread.sleep(Integer.MAX_VALUE);
    }


    @Test
    public void testHttpGetter() throws InterruptedException
    {
        DeferHttpGetter deferHttpGetter = new DeferHttpGetter(TEST_URL);

        for (int i = 0; i < 100; i++)
        {
            Observable<String> observable = deferHttpGetter.responceObservable();
            log.info("test starting...." );
            observable
                    .subscribeOn(Schedulers.io())
                    .subscribe(new Action1<String>()
                    {
                        @Override
                        public void call(String s)
                        {
                            log.info("testHttpGetter s == " + s);
                        }
                    });
        }
        Thread.sleep(Integer.MAX_VALUE);
    }


}
